package com.easychat.entity.enums;

import org.apache.commons.lang3.StringUtils;

public enum GroupStatusEnum {
    DISBAND(0, "解散"),
    NORMAL(1, "正常");

    //状态，0解散，1正常
    private Integer status;
    //描述
    private String description;

    GroupStatusEnum(Integer status, String description) {
        this.status = status;
        this.description = description;
    }

    public Integer getStatus() {
        return status;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据状态返回对应的枚举对象
     * @param status
     * @return
     */
    public static GroupStatusEnum getByStatus(Integer status) {
        for (GroupStatusEnum statusEnum : GroupStatusEnum.values()) {
            if (status.equals(statusEnum.getStatus())) {
                return statusEnum;
            }
        }
        return null;
    }

    /**
     * 返回指定名称的枚举对象
     * @param name
     * @return
     */
    public static GroupStatusEnum getByName(String name) {
        try {
            if (StringUtils.isEmpty(name)) {
                //传入字符串不合法，返回null
                return null;
            }
            return GroupStatusEnum.valueOf(name.toUpperCase());//如果名称转为大写也没有相匹配的枚举对象，会产生异常
        } catch (IllegalArgumentException e) {
            //产生异常，返回null
            return null;
        }
    }
}
